package com.Cychat.post.entity.dto;


import com.Cychat.commons.entity.pojo.Post;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.List;

/**
 * @Auther: 崔航
 * @Date: 2025/10/29:19:31
 * @Description:
 */
@Data
public class PostDTO extends Post {
    private Integer isFavorite;
    private String[] imageUrls;
    private String userIdStr;


    public void setImageUrls(String[] imageUrls) {
        this.imageUrls = imageUrls;
    }

    public String[] getImageUrls() {
        return imageUrls;
    }

    // 添加转换方法
    public static PostDTO fromPost(Post post) {
        PostDTO postDTO = new PostDTO();
        BeanUtils.copyProperties(post, postDTO);

        // 处理图片URL数组
        if (post.getImages() != null && !post.getImages().isEmpty()) {
            String[] imageUrls = post.getImages().split(",");
            postDTO.setImageUrls(imageUrls);
        } else {
            postDTO.setImageUrls(new String[0]);
        }

        // 处理userId转换为字符串
        Long userId = post.getUserId();
        if (userId != null) {
            postDTO.setUserIdStr(userId.toString());
        } else {
            postDTO.setUserIdStr(null); // 或空字符串，根据业务需求决定
        }

        return postDTO;
    }
}